/*
    Android UIML

	Copyright (C) 2010  Bram Goffings (bramgoffings@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation; either version 2.1
	of	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package uiml.android.elements.peers;

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

import uiml.android.elements.UimlElementWithAttributes;

public class DMethod extends UimlElementWithAttributes{
	
	// TODO comment
	private ArrayList<DParam> dparams = new ArrayList<DParam>();
	
	private Script script = null;
	
	private String mapsTo = null;
	private String returnType = null;

	// TODO comment
	public static String IAM = "d-method";
	
	public final String DPARAM = "d-param";
	public final String SCRIPT = "script";
		
	public final String MAPSTO = "maps-to";
	public final String RETURNTYPE = "return-type";
	
	/**
	 * 
	 * @param node
	 */
	public DMethod(Element node) {
		super(node);
		process();
	}

	/**
	 * 
	 */
	@Override
	protected Object clone() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void process() {
		processAttributes();
		super.process();
	}
	
	/**
	 * 
	 */
	@Override
	public void processElement(Element elem) {
		
		if(elem.getTagName().equals(DPARAM))
			dparams.add(new DParam(elem));
		else if(elem.getTagName().equals(SCRIPT))
			script = new Script(elem);
	}
	
	/**
	 * 
	 */
	@Override
	public void processAttributes() {
		
		super.processAttributes();
		
		NamedNodeMap attributes = node.getAttributes();
		
		if(attributes != null) {
			if(attributes.getNamedItem(MAPSTO) != null)
				setMapsTo(attributes.getNamedItem(MAPSTO).getNodeValue());
			if(attributes.getNamedItem(RETURNTYPE) != null)
				setReturnType(attributes.getNamedItem(RETURNTYPE).getNodeValue());
		}
	}

	/**
	 * @param dparams the dparams to set
	 */
	public void setDParams(ArrayList<DParam> dparams) {
		this.dparams = dparams;
	}

	/**
	 * @return the dparams
	 */
	public ArrayList<DParam> getDParams() {
		return dparams;
	}

	/**
	 * @param script the script to set
	 */
	public void setScript(Script script) {
		this.script = script;
	}

	/**
	 * @return the script
	 */
	public Script getScript() {
		return script;
	}

	/**
	 * @param mapsTo the mapsTo to set
	 */
	public void setMapsTo(String mapsTo) {
		this.mapsTo = mapsTo;
	}

	/**
	 * @return the mapsTo
	 */
	public String getMapsTo() {
		return mapsTo;
	}

	/**
	 * @param returnType the returnType to set
	 */
	public void setReturnType(String returnType) {
		this.returnType = returnType;
	}

	/**
	 * @return the returnType
	 */
	public String getReturnType() {
		return returnType;
	}
	

}
